package v3.chapter4.z3_ok;

import java.util.concurrent.locks.Condition; 
import java.util.concurrent.locks.ReentrantLock;

public class Run {

	public static void main(String[] args) { 
		MyService service = new MyService();

		ThreadA a = new ThreadA(service);
		a.start();
	}
}

class ThreadA extends Thread {
	private MyService service;
	public ThreadA(MyService service) {
		super();
		this.service = service;
	}
	@Override
	public void run() {
		service.waitMethod();
	}
}

class MyService{
	private ReentrantLock lock=new ReentrantLock();
	private Condition condition=lock.newCondition();
	
	public void waitMethod() {
		try {
			lock.lock();
			System.out.println("A");
			condition.await();
			System.out.println("B");
		}catch(InterruptedException e) {
			e.printStackTrace();
		}finally {
			lock.unlock();
			System.out.println("锁释放了");
		}
	}
}